# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : group_owner_option_view.py
# Time       ：2023/10/15 14:26
# Author     ：author name
# version    ：python 3.10
# Description：群组owner options
"""
from apis.options import option_ns
from apis.options.views import option_model
from apis.system_oauth.models import SystemUser
from apis.system_oauth.schema.user_schema import GroupOwnerSchema
from public.api_utils.api_decorator import handle_api_error
from public.base_model import db
from public.base_response import generate_response, MarshalModel
from public.base_view import AbstractView

group_owner_marshal = MarshalModel('group_owner', option_ns)


class GroupOwnerOptionView(AbstractView):
    url = '/group_owner_opt'

    def __init__(self, *args, **kwargs):
        super(GroupOwnerOptionView, self).__init__(*args, **kwargs)

    @handle_api_error()
    @option_ns.doc(description='群组owner选项')
    @option_ns.marshal_with(group_owner_marshal.option_response(option_model))
    def get(self):
        """群组owner选项"""
        objs = db.session.query(SystemUser).filter(SystemUser.active == 1).all()
        group_owner = GroupOwnerSchema().dump(objs, many=True)
        return generate_response(group_owner)
